/**
 * 右侧表格字段搜索功能
 * liuhs@meritit.com
 * @create 2018-09-09
 * */
;(function ($) {
    $.widget("tempo.grid_columns_search", {
        options: {
            gridTable: null,
            width: '235px',
        },
        _create: function () {
            var gridTable = this.options.gridTable;
            var width = this.options.width;
            this.element.searchbar({
                auto: true,
                isEnter: true,
                width: width,
                placeholder: TempoUtils.locale("mine.sousuziduanming"),
                onSearch: function (searchContent) {
                    var searchContent = $.trim(searchContent).toUpperCase();
                    var allIds = gridTable.datagrid('getRowIds');
                    for (var i = 0; i < allIds.length; i++) {
                        var data = gridTable.datagrid('getRowData', allIds[i]);
                        var filedName = (data.desc).toUpperCase();
                        if (filedName.indexOf(searchContent) >= 0) {
                            gridTable.find("#" + allIds[i]).show();
                        } else {
                            gridTable.find("#" + allIds[i]).hide();
                        }
                    }
                    //判断全选按钮是否选中
                    var inputs = gridTable.find("input[id^='jqg_']");
                    var flag = true;
                    //记录隐藏的字段个数
                    var num = 0;
                    for (var i = 0; i < inputs.length; i++) {
                        //若当前字段是隐藏的则不需要进行判断
                        var displayCss = $(inputs[i]).parent().parent().css("display");
                        if (displayCss == "none") {
                            num++;
                            continue;
                        }
                        var check = $(inputs[i]).prop('checked');
                        if (!check) {
                            flag = false;
                            break;
                        }
                    }
                    //如果隐藏的字段个数和所有的字段个数一致则全选按钮不选中
                    if (num == inputs.length) {
                        flag = false;
                    }
                    gridTable.parent().parent().prev().find('input').prop("checked", flag);
                }
            });
        },
        _setOption: function (key, val) {

        },
        _bindEvent: function (ul) {

        }
    });
})(jQuery)